//
//  CMLog.swift
//  CMKit
//
//  Created by travel on 2016/12/15.
//  Copyright © 2016年 covermedia. All rights reserved.
//

import Foundation


/// 日志级别定义
public enum CMLogLevel: Int {
    case trace, debug, info, warning, error, none
}

public func <= (a:CMLogLevel, b:CMLogLevel) -> Bool {
    return a.rawValue <= b.rawValue
}


/// 日志
public class CMLog {
    public var logLevel: CMLogLevel = .warning
    
    public static let `default`: CMLog = CMLog()
    
    private init() {
        logLevel = .warning
    }
    
    
    /// 打印 log 到控制台
    ///
    /// - Parameters:
    ///   - object: 对象
    ///   - level: log 级别
    ///   - file: 文件名
    ///   - function: 函数名
    ///   - line: 代码行
    public func log<T>(_ object: T, level: CMLogLevel = .info,  _ file: String = #file, _ function: String = #function, _ line: Int = #line){
        guard logLevel <= level else {
            return
        }
        let filename:String = (file as NSString).lastPathComponent
        debugPrint("[\(level)] \(filename) \(function)[\(line)]: \(object)", terminator: "\n")
    }
}




